package com.ali.asyncgroup.handler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.nio.charset.StandardCharsets;

/**
 * 自定义客户端处理器
 */
public class MyAsyncGroupHandlerClientHandler extends ChannelInboundHandlerAdapter {
    /**
     * 通道激活
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        String message = "hello，服务端";
        System.out.println("发送消息：" + message);
        //构建缓冲区
        ByteBuf byteBuf = Unpooled.copiedBuffer(message, StandardCharsets.UTF_8);
        //写入返回内容
        ctx.write(byteBuf);
        //刷新
        ctx.flush();
    }
}
